/**
* dialog.js
* @category   javascript
* @package    jquery
* @author     dongzh
* @version    
*/
(function($)
{
    var contextData = '_dialog';
    var cachedata = {};
    var arrweebox = new Array();
    var dialogID = 0;
    var getID = function() { return dialogID++; }
    var getElement = function(obj)
    {
        if ($.isPlainObject(obj)) return obj;
        if (typeof (obj) == 'string') return $(obj);
        return obj;
    }
    var errorHtml =
    '            	<div class="floatlayer_wrong">' +
    '            		非常抱歉，数据加载失败' +
    '                </div>' +
    '               <div class="floatlayer_wrong_btn dialog_btn"><a class="btn2" onclick="$(this).closeDialog();" href="javascript:void(0)"><span>关 闭</span></a></div>';

    var tooltipError = '<div class="floatlayer_loading"><div class="floatlayer_loading_error_txt">非常抱歉，数据加载失败</div></div>';

    var weebox = function(opt)
    {
        //var self = this;
        this.id = '';
        this.dh = null;
        this.mh = null;
        this.dc = null;
        this.dt = null;
        this.header = null; //窗口头部，包括关闭按钮
        this.dw = null; //窗口内部装内容的部分，设置宽度时就设置这个
        this.db = null;
        this._dragging = false;
        this.cachedContent = null;
        this.options = null;
        this.contentInited = false;
        this._defaults = {
            src: null, //当弹出confirm对话框时引用的原Jquery对象，在事件函数的时候会以参数传回去
            cache: false,
            type: 'dialog', //类型 message confirm dialog model hover anchor menu等
            title: '',
            width: 0,
            height: 0,
            maskClass: 'dialog_mask', //遮罩层的class名称
            timeout: 0,
            draggable: true,
            modal: true,    //是否模态
            focus: null,
            blur: null,
            left: 0,
            top: 0,
            position: 'center',
            anchorPosition: true, //是否始终定位在某一位置，只在某些状态下有效
            dependElement: null,
            keepHover: null, //要保持浮动窗口的节点，当点击在这些节点内时不会关闭浮动窗口
            overlay: 30,
            icon: '',
            showBackground: true,
            showBorder: true,
            showHeader: true,
            showButton: true,
            showCancel: true,
            showClose: true,
            showOk: true,
            showMask: true, //是否显示遮罩
            okBtnName: '确定',
            cancelBtnName: '取消',
            content: '',
            contentType: 'text',
            contentChange: false,
            clickClose: false,
            animate: '',
            showAnimate: '',
            hideAnimate: '',
            onclose: null, //事件
            onopen: null,
            oncancel: null,
            onok: null,
            
            select: { url: '', type: 'radio', tele: '', vele: '', width: 120, search: false, fn: null }
        };

        var self = this;

        //初始化选项
        this.initOptions = function()
        {
            var tempOpt = opt || {};
            tempOpt.animate = tempOpt.animate || '';
            tempOpt.showAnimate = tempOpt.showAnimate || tempOpt.animate;
            tempOpt.hideAnimate = tempOpt.hideAnimate || tempOpt.animate;
            self.options = $.extend({}, this._defaults, tempOpt);
        };

        //初始化弹窗Box
        this.initBox = function()
        {
            if (self.options.id)
            {
                self.id = self.options.id;
            } else
            {
                self.id = getID();
            }
            var html = '';
            switch (self.options.type)
            {
                case 'anchor': //定位于屏幕某一位置的窗口
                    var iconClass = '';
                    switch (self.options.icon)
                    {
                        case 'success':
                            iconClass = 'success';
                            break;
                        case 'fail':
                            iconClass = 'fail';
                            break;
                        case 'warning':
                            iconClass = 'warning';
                            break;
                        case 'question':
                            iconClass = 'question';
                            break;
                        case 'info':
                            iconClass = 'info';
                            break;
                    }
                    if (self.options.position == 'anchorRight')
                    {
                        html = '<div class="_dialog weedialog dialoganchor" id="_dialog' + self.id + '">' +
						'	<table border="0" cellspacing="0" cellpadding="0">' +
						'		<tr>' +
						'			<td class="dialog-cl"></td>' +
						'			<td>' +
						'				<div class="_container _dialogContent dialog_content anchordialog"></div>' +
						'			</td>' +
						'			<td class="dialog-cr"></td>' +
						'		</tr>' +
						'	</table>' +
						'</div>';
                    } else
                    {
                        html = '<div class="_dialog weedialog dialoganchor" id="_dialog' + self.id + '" style="background:none">' +
                               '     <div class="' + (!(self.options.icon == 'warning' || self.options.icon == 'fail') ? 'over_green' : 'over') + '">' +
	                           '         <div class="' + (!(self.options.icon == 'warning' || self.options.icon == 'fail') ? 'over_green_close' : 'over_close') + '"><!--<a href="javascript:void(0)" class=" _dialogClose">&nbsp;</a>--></div>' +
                               '         <div class="_dialogContent"></div>' +
                               '     </div>' +
        					   '</div>';
                    }
                    break;
                case 'message': //提示窗口
                case 'confirm': //确认窗口
                    var iconClass = '';
                    switch (self.options.icon)
                    {
                        case 'success':
                            iconClass = 'success';
                            break;
                        case 'fail':
                            iconClass = 'fail';
                            break;
                        case 'warning':
                            iconClass = 'warning';
                            break;
                        case 'question':
                            iconClass = 'question';
                            break;
                        case 'info':
                            iconClass = 'info';
                            break;
                    }
                    html = '<div class="_dialog weedialog" id="_dialog' + self.id + '">' +
                    '    <div class="dialog-header _dialogHeader"><div class="dialog-tl"></div><span class="_title">系统消息</span><a href="javascript:void(0)" class="dialog_close _dialogClose" title="关闭"></a></div> ' +
						'	<table border="0" cellspacing="0" cellpadding="0">' +
						'		<tr>' +
						'			<td class="dialog-cl"></td>' +
						'			<td>' +
						'				<div class="_container dialog_content"><div class="_dialogContent ' + iconClass + '"></div>' +
						'				<div class="_dialog-button dialog_selectbt">' +
						'					<a href="javascript:void(0)" class="btn2 dialog-ok _dialogOk"><span>确定</span></a>' +
						'					<a href="javascript:void(0)" class="btn2 dialog-cancel _dialogCancel"><span>取消</span></a>' +
						'				</div>' +
						'</div>' +
						'			</td>' +
						'			<td class="dialog-cr"></td>' +
						'		</tr>' +
						'	</table>' +
						'</div>';
                    break;
                case 'modal': //模式窗口
                    //self.options.maskClass='resumemask';
                case 'dialog': //非模式窗口
                    html = '<div class="_dialog weedialog" id="_dialog' + self.id + '">' +
                        '<div class="dialog-header _dialogHeader"><div class="dialog-tl"></div><span class="_title">系统消息</span><a href="javascript:void(0)" class="dialog_close _dialogClose" title="关闭"></a></div> ' +
						'	<table border="0" cellspacing="0" cellpadding="0">' +
						'		<tr>' +
						'			<td class="dialog-cl"></td>' +
						'			<td>' +
						'				<div class="_container _dialogContent dialog_content"></div>' +
						'			</td>' +
						'			<td class="dialog-cr"></td>' +
						'		</tr>' +
						'	</table>' +
						'</div>';
                    break;
                case 'menu': //菜单
                    html = '<div class="_dialog weedialog dialogosilde" id="_dialog' + self.id + '">' +
						'				<div class="_container _dialogContent dialog_content"></div>' +
						'</div>';
                    break;
                case 'hover': //浮动窗口
                    html = '<div class="_dialog weedialog" id="_dialog' + self.id + '">' +
						'				<div class="_container _dialogContent dialog_content"></div>' +
						'</div>';
                    break;
                case 'tooltip': //气泡
                    html = '<div class="_dialog floatlayer_con _tooltip" style="" id="_dialog' + self.id + '">' +
                           '    <div id="_arrow" class="floatlayer_arrow_left"></div>' +
                           '    <table cellpadding="0" cellspacing="0" >' +
        	               '         <tbody>' +
            	           '             <tr class="floatlayer_con_top">' +
                           '                 <td class="floatlayer_con_top_l" width="5">&nbsp;</td>' +
                           '                 <td class="floatlayer_con_top_c">&nbsp;</td>' +
                           '                 <td class="floatlayer_con_top_r" width="5">&nbsp;</td>' +
                           '             </tr>' +
                           '             <tr class="floatlayer_con_con">' +
                	       '                 <td class="floatlayer_con_con_l">&nbsp;</td>' +
                           '                 <td class="floatlayer_con_con_c _container _dialogContent">' +
                           '                 </td>' +
                           '                 <td class="floatlayer_con_con_r">&nbsp;</td>' +
                           '             </tr>' +
                           '             <tr class="floatlayer_con_bot">' +
                	       '                 <td class="floatlayer_con_bot_l">&nbsp;</td>' +
                           '                 <td class="floatlayer_con_bot_c">&nbsp;</td>' +
                           '                 <td class="floatlayer_con_bot_r">&nbsp;</td>' +
                           '             </tr>' +
                           '         </tbody>' +
                           '    </table>' +
                           '</div>';
                    html = '<div class="_dialog _tooltip floatlayer" id="_dialog' + self.id + '">' +
                            '        <div id="_arrow" class="floatlayer_arrow_left"></div>' +
                            '    <div class=" _container _dialogContent floatlayer_con">' +
                    //'        <div class=" test" style="_white-space:nowrap;"></div>' +
                            '    </div>' +
                            '</div>';
                    break;
                case 'img': //图片
                    html = '<div class="_dialog" id="_dialog' + self.id + '"></div>';
                    break;
            }
            //如果是菜单，加到指定的位置里
            if (self.options.type == 'menu')
            {
                self.dh = $(html).appendTo(self.options.container || 'body').css({
                    position: 'absolute',
                    //    overflow: 'hidden',
                    zIndex: getZIndex(),
                    left: -1000,
                    top: -1000
                });
            } else
            {
                self.dh = $(html).appendTo('body').css({
                    position: 'absolute',
                    //    overflow: 'hidden',
                    zIndex: getZIndex(),
                    left: -1000,
                    top: -1000
                });
            }
            if (self.options.type == 'message' || self.options.type == 'confirm')
            {
                self.dh.addClass('confirmWidth');
            }
            self.dc = self.find('._dialogContent');
            self.dt = self.find('._title');
            self.dw = self.find('._container');
            self.header = self.find('._dialogHeader');
            self.db = self.find('._dialogButton');

            if (self.options.boxclass)
            {
                self.dh.addClass(self.options.boxclass);
            }
            if (self.options.height > 0)
            {
                self.dc.css('height', self.options.height);
            }
            if (self.options.width > 0)
            {
                self.dw.css('width', self.options.width);
            }
            if (self.options.position == 'anchorRight')
            {
                self.dh.addClass('anchorRight');
            }

            self.setTitle(self.options.title);
           if(self.options.showMask) self.dh.bgiframe();
            self.dh.data(contextData, self);
        }

        //初始化遮照
        this.initMask = function()
        {
            if (self.options.showMask && (self.options.type == 'modal' || self.options.type == 'message' || self.options.type == 'confirm'))
            {
                /*if ($.browser.msie) 
                {
                h = document.compatMode == "CSS1Compat" ? document.documentElement.clientHeight : document.body.clientHeight;
                w = document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth : document.body.clientWidth;
                } else */
                var h, w;
                var wnd = $(window);
                var doc = $(document);
                if (doc.height() > wnd.height())
                {
                    h = doc.height() - 5; //self.bheight();
                    w = doc.width() - 21;
                } else
                {
                    h = doc.height() - 5; //self.bheight();
                    w = doc.width() - 5;
                }
                //临时用于type=modeal的遮罩层样式
                if(self.options.type == 'modal')self.options.maskClass='resumemask';

			    var isIE6=$.browser.msie&&($.browser.version=="6.0");
			    if(isIE6)
			    {
                    self.mh = $('<div id="_mask' + self.id + '" class="' + self.options.maskClass + '"></div>')
				    .appendTo('body').hide().css(
				    {
				        width: w,
				        height: h,
				        position:'absolute',
				        zIndex: getZIndex()
				    }).animate({opacity: 0.5},500).bgiframe();
			        $(window).resize(function()
                    {
                        var h, w;
                        var wnd = $(window);
                        var doc = $(document);
                        if (doc.height() > wnd.height())
                        {
                            h = doc.height() - 5; //self.bheight();
                            w = doc.width() - 21;
                        } else
                        {
                            h = doc.height() - 5; //self.bheight();
                            w = doc.width() - 5;
                        }
                        self.mh.css({ height: h, width: w });
                    });
			    }
			    else
			    {
                    self.mh = $('<div id="_mask' + self.id + '" class="' + self.options.maskClass + '"></div>')
				    .appendTo('body').hide().css(
				    {
				        //width: w,
				        //height: h,
				        zIndex: getZIndex()
				    }).animate({opacity: 0.5},500).bgiframe();			    
			    }
			    
            }
        }

        this.setTitle = function(title)
        {
            if (title == '')
            {
                self.dt.html('&nbsp;');
            } else
            {
                self.dt.html(title);
            }
        }

        //初始化弹窗内容
        this.initContent = function(content)
        {
            self.dh.find("._dialogOk").val(self.options.okBtnName);
            self.dh.find("._dialogCancel").val(self.options.cancelBtnName);
            if (self.options.title == '')
            {
                self.dt.html('&nbsp;');
            } else
            {
                self.dt.html(self.options.title);
            }
            if (!self.options.showHeader)
            {
                self.header.hide();
            }
            if (!self.options.showBorder)
            {
                self.dh.css({ border: 'none' });
                self.dc.css({ border: 'none' });
            }
            if (!self.options.showBackground)
            {
                self.dh.css({ background: 'none' });
                self.dc.css({ background: 'none' });
            }
            if (!self.options.showButton)
            {
                self.dh.find('._dialogButton').hide();
            }
            if (!self.options.showCancel)
            {
                self.dh.find('._dialogCancel').hide();
            }
            if (!self.options.showClose)
            {
                self.dh.find('._dialogClose').hide();
            }
            if (!self.options.showOk)
            {
                self.dh.find("._dialogOk").hide();
            }

            //如果没有图标内容不偏移
            if (!self.options.icon)
            {
                //self.dc.css({padding:0});
            }

            if (self.options.contentType == "selector")
            {
                var content = getElement(self.options.content).clone(true);
                content.show();
                content.css('display', 'block');
                self.setContent(content);
                self.contentInited = true;
                //if have checkbox do
                //选中里面的多选框，暂时没得用
                /*
                var cs = $(self.selector).find(':checkbox');
                self.dc.find(':checkbox').each(function(i) 
                {
                self.checked = cs[i].checked;
                });*/
                //$(self.selector).empty(); //清空原来的div
                //self.show();
                //self.focus();
                self.onopen();
            } else if (self.options.contentType == "ajax")
            {
                self.setLoading();
                var stop = self.stopLoading;
                setTimeout(stop, 8000);
                //this.show();
                //this.dh.find(".dialog-button").hide();
                var url = self.options.content;
                if (self.options.type == 'tooltip')
                {
                    if (url.indexOf('?') == -1)
                    {
                        url += "?_tooltip=true";
                    } else
                    {
                        url += "&_tooltip=true";
                    }
                }
                $.ajax(
                {
                    url: url,
                    dataType: 'html',
                    success: function(data)
                    {
                        self.stopLoading();
                        if (self.options.type == 'tooltip')
                        {
                            if (data == 'needPersonLogin')
                            {
                                try
                                {
                                    self.hide();
                                } catch (e) { }
                                checkPersonLogin();
                                return;
                            } else if (data == 'needCompanyLogin')
                            {
                                try
                                {
                                    self.hide();
                                } catch (e) { }
                                checkCompanyLogin();
                                return;
                            }
                        }
                        self.setContent(data);
                        self.innerShow(true);
                        if (self.options.cache)
                        {
                            self.cachedContent = data;
                        }
                        self.contentInited = true;
                        //self.show();
                        //self.focus();
                        self.onopen();
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown)
                    {
                        self.stopLoading();
                        if (self.options.type == 'tooltip')
                        {
                            self.setContent(tooltipError);
                        } else
                        {
                            self.setContent(errorHtml);
                        }
                        self.innerShow(true);
                        if (self.options.cache)
                        {
                            self.cachedContent = data;
                        }
                        self.contentInited = true;
                        //self.show();
                        //self.focus();
                        self.onopen();
                    }
                });
            } else if (self.options.contentType == "iframe")
            { /*加入iframe使程序可以直接引用其它页面 by ePim*/
                var html = '<style type="text/css">';
                html += ('\n.dialog-box .dialog_content{padding:0px;}');
                html += ('\n</style>');
                html += ('<iframe class="dialogIframe" src="' + self.options.content + '" width="100%" height="100%" frameborder="0"></iframe>');
                self.setContent(html);
                self.contentInited = true;
                self.onopen();
                //self.show();
            } else if (self.options.contentType == 'img')
            {
                var html = '<div class="floatlayer_pic"><img src="' + self.options.content + '" /></div>';
                self.setContent(html);
                self.contentInited = true;
                self.onopen();
            } else
            {
                self.setContent(self.options.content);
                self.contentInited = true;
                //self.show();
                //self.focus();
                self.onopen();
            }
        }

        //初始化弹窗事件
        this.initEvent = function()
        {
            self.dh.find("._dialogClose, ._dialogCancel, ._dialogOk").unbind('click').click(function() { $(this).closeDialog(); return false; });
            //当用户按下键盘按钮时触取消按钮
            self.dh.keydown(function(event)
            {
                var e = $.event.fix(event);
                //esc键， 等效于退出按钮
                if (e.keyCode == 27)
                {
                    var cancell = self.dh.find('._dialogCancel');
                    if (cancell.is(':visible'))
                    {
                        cancell.click();
                    } else if (self.dh.find('._dialogClose').is(':visible'))
                    {
                        self.dh.find('._dialogClose').click();
                    }
                }
            });
            self.dh.mousedown(function() { self.dh.css('z-index', getZIndex()) });
            if (self.options.onok)
            {
                self.setOnok(self.options.onok);
            }

            if (self.options.oncancel)
            {
                self.setOncancel(self.options.oncancel);
            }

            if (self.options.timeout > 0)
            {
                window.setTimeout(self.close, (self.options.timeout * 1000));
            }
            if (self.options.type == 'hover' || self.options.type == 'menu')
            {
                $('body').mousedown(function(event)
                {
                    var e = $.event.fix(event);
                    var src = e.target;
                    var keep = false;
                    if (self.dh[0] == src || $.contains(self.dh[0], src))
                    {
                        keep = true;
                    }
                    //如果是在模式窗口内也不关闭
                    $('._dialog').each(function()
                    {
                        if ($.contains(this, src)) keep = true;
                    });
                    if (!keep && self.options.keepHover)
                    {
                        if ($.isArray(self.options.keepHover))
                        {
                            try
                            {
                                for (var i in self.options.keepHover)
                                {
                                    if (typeof self.options.keepHover[i] == 'string')
                                    {
                                        $(self.options.keepHover[i]).each(function()
                                        {
                                            if (this == src || $.contains(this, src))
                                            {
                                                keep = true;
                                            }
                                        });
                                    } else
                                    {
                                        var el = self.options.keepHover[i][0];
                                        if (el == src || $.contains(el, src))
                                        {
                                            keep = true;
                                        }
                                    }

                                }
                            } catch (e) { }
                        } else
                        {
                            try
                            {
                                if (typeof self.options.keepHover == 'string')
                                {
                                    $(self.options.keepHover).each(function()
                                    {
                                        if (this == src || $.contains(this, src))
                                        {
                                            keep = true;
                                        }
                                    });
                                } else
                                {
                                    var el = self.options.keepHover[0];
                                    if (el == src || $.contains(el, src))
                                    {
                                        keep = true;
                                    }
                                }
                            } catch (e) { }
                        }
                    }
                    if (!keep) self.close();
                });

                self.dh.find('tr').each(function()
                {
                    $(this).mouseover(function() { $(this).addClass('cu'); }).mouseout(function() { $(this).removeClass('cu'); });
                });
            }
            self.drag();
        }

        //设置onok事件
        this.setOnok = function(fn)
        {
            //self.dh.find(".dialog-ok").unbind('click');
            if (typeof (fn) == "function")
            {
                var src = self.options.src;
                self.dh.find("._dialogOk").click(function() { fn(src); });
            } else if (typeof fn == 'number')
            {
                self.dh.find("._dialogOk").click(function()
                {
                    window.history.go(fn);
                });
            } else if (typeof fn == 'string')
            {
                self.dh.find("._dialogOk").click(function()
                {
                    window.location = fn;
                });
            }
        }
        //设置onOncancel事件
        this.setOncancel = function(fn)
        {
            //self.dh.find(".dialog-cancel").unbind('click');
            if (typeof (fn) == "function")
            {
                var src = self.options.src;
                self.dh.find("._dialogClose,._dialogCancel").click(function() { fn(src) });
            } else if (typeof (fn) == "number")
            {
                self.dh.find("._dialogClose,._dialogCancel").click(function() { window.history.go(fn); });
            } else if (typeof (fn) == "function")
            {
                self.dh.find("._dialogClose,._dialogCancel").click(function() { window.location = fn; });
            }
        }

        //打开前的回弹函数
        this.onopen = function()
        {
            if (typeof (self.options.onopen) == "function")
            {
                self.options.onopen(self);
            }
        }

        //关闭事件
        this.onclose = function()
        {
            //如果是加载的页面，清空高亮显示的行
            if (self.options.contentType == 'ajax' && (self.options.type == 'modal' || self.options.type == 'dialog'))
            {
                clearHighLight();
            }
            if (typeof self.options.onclose == 'number')
            {
                window.history.go(self.options.onclose);
            } else if (typeof self.options.onclose == 'string')
            {
                setTimeout('window.location = "' + self.options.onclose + '";', 100);

            } else if (typeof (self.options.onclose) == "function")
            {
                var src = self.options.src;
                self.options.onclose(src);
            }
        }

        //弹窗拖拽
        this.drag = function()
        {
            //取消拖动效果，因为加上了iframe后拖动不了
            return;
            if (self.options.draggable && self.options.showHeader)
            {
                var header = self.dh.find('._dialogHeader');
                header.css('cursor', 'move');
                var mouseMove = function(event)
                {
                    var h = self;
                    //var o = document;
                    var width = h.dh.width();
                    var height = h.dh.height();
                    if (window.getSelection)
                    {
                        window.getSelection().removeAllRanges();
                    } else
                    {
                        document.selection.empty();
                    }

                    var left = event.clientX - h.mx; // Math.max(event.clientX - h.mx, 0);
                    var top = event.clientY - h.my; //Math.max(event.clientY - h.my, 0);
                    h.dh.css({ left: left, top: top });
                };
                var mouseUp = function()
                {
                    var h = self;
                    if (h.releaseCapture)
                    {
                        h.releaseCapture();
                    }
                    $(document).unbind('mousemove');
                    $(document).unbind('mouseup');
                };
                var mouseDown = function(event)
                {
                    var dhleft = parseInt(self.dh.css('left').replace('px'));
                    var dhtop = parseInt(self.dh.css('top').replace('px'));
                    self.mx = event.clientX - dhleft; // event.clientX;
                    self.my = event.clientY - dhtop; //event.clientY;
                    if (self.setCapture)
                    {
                        self.setCapture();
                    }

                    $(document).mousemove(mouseMove).mouseup(mouseUp);
                };

                header.mousedown(mouseDown);
            }
        }

        //增加一个按钮
        this.addButton = function(opt)
        {
            opt = opt || {};
            opt.title = opt.title || 'OK';
            opt.bclass = opt.bclass || 'dialog-btn1';
            opt.fn = opt.fn || null;
            opt.index = opt.index || 0;
            var btn = $('<input type="button" class="' + opt.bclass + '" value="' + opt.title + '">').click(function()
            {
                if (typeof opt.fn == "function") opt.fn(self);
            });
            if (opt.index < self.db.find('input').length)
            {
                self.db.find('input:eq(' + opt.index + ')').before(btn);
            } else
            {
                self.db.append(opt);
            }
        }
        this.hide = function(fn)
        {
            if (typeof self.options.hideAnimate == "string")
            {
                self.dh.hide(self.options.animate, fn);
            } else
            {
                self.dh.animate(self.options.hideAnimate.animate, self.options.hideAnimate.speed, "", fn);
            }
        }
        //设置弹窗焦点
        this.focus = function()
        {/*
            if (self.options.focus)
            {
                self.dh.find(self.options.focus).focus(); //TODO IE中要两次
                self.dh.find(self.options.focus).focus();
            } else
            {
                self.dh.find('._dialogCancel').focus();
            }*/
        }
        //在弹窗内查找元素
        this.find = function(selector)
        {
            return self.dh.find(selector);
        }
        //设置加载加状态
        this.setLoading = function()
        {
            //var loading = $('<div >正在加载中</div>');
            //$('body').append(loading);
            //loading.css({ 'z-index': self.dh.css('z-index') + 1 });
            //var width = Math.max(self.dh.outerWidth(), 40);
            //var height = Math.max(self.dh.outerHeight(), 70);
            //loading.css({ width: width, height: height });
            //self.initPosition(loading);
            //self.loading = loading;
            self.setContent('<div class="floatlayer_loading"><div class="floatlayer_loading_con"></div></div>');
        }
        //停止加载状态
        this.stopLoading = function()
        {
            try
            {
                if(self.loading&&typeof self.loading != "undefined")
                {
                  self.loading.remove();
                }
            } catch (e) { } finally
            {
                self.loading = null;
                return;
            }
        }

        this.setWidth = function(width)
        {
            self.dw.width(width);
        }
        //取得标题
        this.getTitle = function()
        {
            return self.dt.html();
        }

        //设置内容
        this.setContent = function(content)
        {
            if (typeof content == 'string')
            {
                self.dc.html(content);
            } else
            {
                self.dc.append(content);
            }
            if (self.options.height > 0)
            {
                self.dc.css('height', self.options.height);
            } else
            {
                self.dc.css('height', '');
            }
            if (self.options.width > 0)
            {
                //self.dh.css('width', self.options.width);
            } else
            {
                self.dh.css('width', '');
            }
            if (self.options.showButton)
            {
                self.dh.find("._dialog-button").show();
            }
        }

        //取得内容
        this.getContent = function()
        {
            return self.dc.html();
        }

        //使能按钮
        this.disabledButton = function(btname, state)
        {
            self.dh.find('._dialog' + btname).attr("disabled", state);
        }
        //隐藏按钮
        this.hideButton = function(btname)
        {
            self.dh.find('._dialog' + btname).hide();
        }
        //显示按钮
        this.showButton = function(btname)
        {
            self.dh.find('._dialog' + btname).show();
        }
        //设置按钮标题
        this.setButtonTitle = function(btname, title)
        {
            self.dh.find('._dialog' + btname).val(title);
        }
        //操作完成
        this.next = function(opt)
        {
            opt = opt || {};
            opt.title = opt.title || self.getTitle();
            opt.content = opt.content || "";
            opt.okname = opt.okname || "确定";
            opt.width = opt.width || 260;
            opt.onok = opt.onok || self.close;
            opt.onclose = opt.onclose || null;
            opt.oncancel = opt.oncancel || null;
            opt.hideCancel = opt.hideCancel || true;
            self.setTitle(opt.title);
            self.setButtonTitle("ok", okname);
            self.setWidth(width);
            self.setOnok(opt.onok);
            if (opt.content != "") self.setContent(opt.content);
            if (opt.hideCancel) self.hideButton("cancel");
            if (typeof (opt.onclose) == "function") self.setOnclose(opt.onclose);
            if (typeof (opt.oncancel) == "function") self.setOncancel(opt.oncancel);
            self.show();
        }

        this.toggle = function()
        {
            if (self.options.id && self.dh && self.dh.length > 0)
            {
                try
                {
                    var d = self; //$('#_dialog' + self.options.id).data(contextData);
                    if (d.dh.is(':visible'))
                    {
                        d.close();
                    } else
                    {
                        d.show();
                    }
                } catch (e) { alert('toggle:' + e.message); }
            } else
            {
                if (self.dh && self.dh.length && self.dh.is(':visible'))
                {
                    self.close();
                } else
                {
                    self.show();
                }
            }
        }

        //显示弹窗
        this.show = function()
        {
            //关闭现有的层
            if (self.options.id)
            {
                try
                {
                    //有错
                    var d = $('#_dialog' + self.options.id); //.data(contextData);
                    //d.close();
                    if (d.size() > 0) return;
                } catch (e) { }
            }

            var dialog = self.options.id ? self : $.extend({}, self);
            dialog.initMask();
            dialog.initBox();
            dialog.initContent();
            // if (dialog.options.contentType != 'ajax')
            {
                dialog.innerShow();
            }

            return false;
        }

        this.innerShow = function(isComplete)
        {

            var dialog = self;
            dialog.initEvent();
            dialog.initPosition();
            if (dialog.mh)
            {
                dialog.mh.show();
            }

            if (dialog.options.type == 'menu')//菜单采用滑出的动画效果
            {
                //var height = dialog.dh.height();
                //dialog.dh.height(0);
                dialog.dh.show();
                if (dialog.options.position == 'under')
                {
                    //dialog.dh.animate({ height: height }, 200);
                } else if (dialog.options.position == 'top')
                {
                    var top = dialog.dh.offset().top;
                    //dialog.dh.css({ top: top + height });
                    //dialog.dh.animate({ height: height, top: top }, 200);
                }

            } else if (dialog.options.showAnimate == "toggle" || dialog.options.showAnimate == "slide" || dialog.options.showAnimate == "fade")
            {
                switch (dialog.options.animate)
                {
                    case 'toggle':
                        dialog.dh.hide().show(400);
                        break;
                    case 'slide':
                        dialog.dh.hide().slideDown(400);
                        break;
                    case 'fade':
                        dialog.dh.hide().fadeIn(400, function()
                        {
                            //聚集到确定或关闭按钮
                            var ok = self.dh.find('._dialogOk');
                            if (ok.is(':visible'))
                            {
                                ok.focus();
                            } else
                            {
                                self.dh.find('._dialogClose').focus();
                            }
                        });
                        break;
                }
            } else if (dialog.options.showAnimate)
            {
                dialog.dh.animate(dialog.options.showAnimate.animate, dialog.options.showAnimate.speed, function()
                {
                    //聚集到确定或关闭按钮
                    var ok = self.dh.find('._dialogOk');
                    if (ok.is(':visible'))
                    {
                        ok.focus();
                    } else
                    {
                        self.dh.find('._dialogClose').focus();
                    }
                });
            } else
            {
                dialog.dh.show();
                //聚集到确定或关闭按钮
                var ok = self.dh.find('._dialogOk');
                if (ok.is(':visible'))
                {
                    ok.focus();
                } else
                {
                    self.dh.find('._dialogClose').focus();
                }
            }

            if (self.options.type == 'tooltip' && self.options.keepHover && isComplete)
            {
                var depend = getElement(self.options.dependElement);
                var left = Math.min(depend.offset().left, self.dh.offset().left);
                var right = Math.max(depend.offset().left + depend.width(), self.dh.offset().left + self.dh.width());
                var top = Math.min(depend.offset().top, self.dh.offset().top);
                var bottom = Math.max(depend.offset().top + depend.height(), self.dh.offset().top + self.dh.height());
                var closeFn = self.close;
                // alert(left + ':' + right + '   :   ' + top + ':' + bottom);
                var move = function(event)
                {
                    var wnd = $(window);
                    var e = $.event.fix(event);
                    var x = e.clientX + wnd.scrollLeft();
                    var y = e.clientY + wnd.scrollTop();

                    if (x >= left && x <= right && y <= bottom && y >= top) return;
                    closeFn();
                    $('body').unbind('mousemove', move);
                };
                $('body').mousemove(move);
            }
            if(self.options.showMask)self.dh.bgiframe();
        }

        //关闭弹窗
        this.close = function(n)
        {
            self.onclose();
            //查看自动完成的提示窗口将其关闭,Email提示层
//            try
//            {
//                $('.em_divtip').remove();
//            } catch (e) { }

            //设置关闭后的焦点
            if (self.options.blur)
            {
                $(self.options.blur).focus();
            }
            //从数组中删除
            for (i = 0; i < arrweebox.length; i++)
            {
                if (arrweebox[i].dh.get(0) == self.dh.get(0))
                {
                    arrweebox.splice(i, 1);
                    break;
                }
            }
            //关闭回调，用于移除对象
            var closeCallback = function()
            {
                self.dh.remove();
                if (self.mh)
                {
                    self.mh.animate({opacity:0},{complete:function()
																   {
																   self.mh.remove();
																  }});
                }
            };
            if (self.options.type == 'menu')//菜单采用滑出的动画效果
            {
                var height = self.dh.height();
                if (self.options.position == 'under')
                {
                    //self.dh.animate({ height: 0 }, 200, closeCallback);
                } else if (self.options.position == 'top')
                {
                    var top = self.dh.offset().top + height;
                    //self.dh.css({top:top-height});
                    //self.dh.animate({ height: 0, top: top }, 200, closeCallback);
                }
                self.dh.hide();
                closeCallback();
            } else if (self.options.showAnimate == "toggle" || self.options.showAnimate == "slide" || self.options.showAnimate == "fade")
            {
                switch (self.options.animate)
                {
                    case 'toggle':
                        self.dh.hide(400, closeCallback);
                        break;
                    case 'slide':
                        self.dh.slideUp(400, closeCallback);
                        break;
                    case 'fade':
                        self.dh.fadeOut(400, closeCallback);
                        break;
                }
            } else if (self.options.showAnimate)
            {
                self.dh.animate(self.options.showAnimate.animate, self.options.showAnimate.speed, closeCallback);
            } else
            {
                self.dh.hide();
                closeCallback();
            }
            // self.hide();
        }
        //取得遮照高度
        this.bheight = function()
        {
            if ($.browser.msie && $.browser.version < 7)
            {
                var scrollHeight = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
                var offsetHeight = Math.max(document.documentElement.offsetHeight, document.body.offsetHeight);

                if (scrollHeight < offsetHeight)
                {
                    return $(window).height();
                } else
                {
                    return scrollHeight;
                }
            } else
            {
                return $(document).height();
            }
        }
        //取得遮照宽度
        this.bwidth = function()
        {
            if ($.browser.msie && $.browser.version < 7)
            {
                var scrollWidth = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
                var offsetWidth = Math.max(document.documentElement.offsetWidth, document.body.offsetWidth);

                if (scrollWidth < offsetWidth)
                {
                    return $(window).width();
                } else
                {
                    return scrollWidth;
                }
            } else
            {
                return $(document).width();
            }
        }
        //初始化窗口位置
        this.initPosition = function(obj)
        {
            var src = obj || self.dh;
            var left = 0, top = 0;
            if (self.options.type == 'tooltip')
            {
                var arrowSize = 7;
                var arrowClass = 'floatlayer_arrow_left';
                var depend = getElement(self.options.dependElement);
                var offset = depend.offset();
                left = offset.left;
                top = offset.top + depend.outerHeight();
                var arrowLeft = 0;
                var arrowTop = 0;
                var doc = $(document);
                var wnd = $(window);
                var toTop = function()
                {
                    top = offset.top - src.outerHeight() - arrowSize;
                    left = offset.left - ((src.outerWidth() - depend.outerWidth()) / 2);
                    var of = 0;
                    if (left < 0)
                    {
                        of = left * -1;
                    } else if (left + src.outerWidth() > wnd.scrollLeft() + wnd.width())
                    {
                        // of = doc.width() - (left + src.outerWidth());
                        of = left + src.outerWidth() - wnd.scrollLeft() - wnd.width();
                    }
                    left += of;
                    arrowTop = src.innerHeight() - 1;
                    arrowLeft = src.outerWidth() / 2 + of - arrowSize / 2;
                    arrowClass = 'floatlayer_arrow_bottom';
                    return top >= 0;
                };
                var toBottom = function()
                {
                    top = offset.top + depend.outerHeight() + arrowSize;
                    left = offset.left - ((src.outerWidth() - depend.outerWidth()) / 2);
                    var of = 0;
                    if (left < 0)
                    {
                        of = left * -1;
                    } else if (left + src.outerWidth() > wnd.scrollLeft() + wnd.width())
                    {
                        //of = doc.width() - (left + src.outerWidth());
                        of = left + src.outerWidth() - wnd.scrollLeft() - wnd.width();
                    }
                    left += of;
                    arrowTop = -1 * arrowSize;
                    arrowLeft = src.outerWidth() / 2 + of - arrowSize / 2;
                    arrowClass = 'floatlayer_arrow_top';
                    return top + src.outerHeight() < doc.height();
                };
                var toLeft = function()
                {
                    top = offset.top - (src.outerHeight() - depend.outerHeight()) / 2;
                    left = offset.left - src.outerWidth() - arrowSize;
                    var of = 0;
                    if (top + src.outerHeight() > wnd.scrollTop() + wnd.height())
                    {
                        //of = (top + src.outerHeight()) - doc.height();
                        of = top + src.outerHeight() - wnd.scrollTop() - wnd.height();
                    } else if (top < 0)
                    {
                        of = top * -1;
                    }
                    top -= of;
                    arrowTop = src.outerHeight() / 2 + of - arrowSize / 2;
                    arrowLeft = src.width() - 1;
                    arrowClass = 'floatlayer_arrow_right';
                    return left >= 0;
                };
                var toRight = function()
                {
                    top = offset.top - (src.outerHeight() - depend.outerHeight()) / 2;
                    left = offset.left + depend.outerWidth() + arrowSize;
                    var of = 0;
                    if (top + src.outerHeight() > wnd.scrollTop() + wnd.height())
                    {
                        //of = (top + src.outerHeight()) - doc.height();
                        of = top + src.outerHeight() - wnd.scrollTop() - wnd.height();
                    } else if (top < 0)
                    {
                        of = top * -1;
                    }
                    top -= of;
                    arrowTop = src.outerHeight() / 2 + of - arrowSize / 2;
                    arrowLeft = -1 * arrowSize;
                    arrowClass = 'floatlayer_arrow_left';

                    return left + src.outerWidth() <= doc.width();
                };

                if (self.options.position == 'top')
                {
                    if (!toTop()) toBottom();
                } else if (self.options.position == 'bottom')
                {
                    if (!toBottom()) toTop();
                } else if (self.options.position == 'left')
                {
                    if (!toLeft()) toRight();
                } else
                {
                    if (!toRight()) toLeft();
                }
                src.css({ left: left, top: top });
                //self.dw.width(src.width() - 10);
                //self.dw.height(src.height() - 20);
                src.find('#_arrow').addClass(arrowClass);
                src.find('#_arrow').css({ left: arrowLeft, top: arrowTop });
                return;
            } else if (self.options.position == 'center' || self.options.type == 'modal' || self.options.position == 'anchor' || self.options.position == 'anchorRight')//绝对定位于某个位置
            {
                self.anchorToPos(src);
                if (self.options.anchorPosition)
                {
                    var anchor = function(s)
                    {
                        return function() { self.anchorToPos(s); };
                    } (src);

                    anchor = $.proxy(anchor, self);

                    //  2011-05-20 zhangyu  update
                    //  取消弹出窗口根据浏览的改变和重新设置位置事件
                    //  只有当不支持fixed属性的时候才需要不断修正位置
                    
                    /*
                    if ($.support.fixed)
                    {
                        $(window).resize(anchor);
                        $(document).resize(anchor);
                    } else
                    {
                        //$(window).scroll(anchor).resize(anchor);
                        $(document).resize(anchor);
                    }
                    */
                }
                return;
            } else
            {
                var depend = getElement(self.options.dependElement);
                var offset = depend.offset();
                var wnd = $(window);
                var doc = $(document);

                var toDepend = function()
                {
                    left = depend.offset().left;
                    if (offset.left + self.dh.outerWidth() > doc.width())
                    {
                        left = doc.width() - src.outerWidth() - 10;
                    }
                    top = offset.top - src.outerHeight();
                    if (offset.top + self.dh.outerHeight() > doc.height())
                    {
                        top = doc.height() - src.outerHeight() - 10;
                    }
                }

                var toTop = function()
                {
                    var dependTop = 0;
                    if (self.options.type == 'menu' && self.options.container)
                    {
                        offset = depend.position();
                        dependTop = depend.offset().top;
                    }

                    left = offset.left;
                    top = offset.top - src.outerHeight();
                    if (left + self.dh.outerWidth() > wnd.scrollLeft() + wnd.width()) left -= left + self.dh.outerWidth() - wnd.scrollLeft() - wnd.width()
                    //不能超过屏幕边框
                    //if (left + self.dh.outerWidth() > wnd.scrollLeft() + wnd.width()) left -= left + src.outerWidth() - wnd.scrollLeft() - wnd.width();
                    //if (top + src.outerHeight() > wnd.height() + wnd.scrollTop()) top -= top + src.outerHeight() - wnd.height() - wnd.scrollTop();
                    if (self.options.type == 'menu') top++;
                    return top + dependTop >= wnd.scrollTop();
                }

                var toUnder = function()
                {
                    var dependTop = 0;
                    if (self.options.type == 'menu' && self.options.container)
                    {
                        offset = depend.position();
                        //下面的修正是针对简历助手进行的调整，只有简历助手才需要相对于父容器进行定位，其它的是相对于document
                        offset.top += 3;
                        offset.left += 10;
                        dependTop = depend.offset().top;
                    }
                    left = offset.left;
                    top = offset.top + depend.outerHeight();
                    //不能超过屏幕边框
                    //if (left + self.dh.outerWidth() > wnd.scrollLeft() + wnd.width()) left -= left + src.outerWidth() - wnd.scrollLeft() - wnd.width();
                    //if (top + src.outerHeight() > wnd.height() + wnd.scrollTop()) top -= top + src.outerHeight() - wnd.height() - wnd.scrollTop();
                    if (self.options.type == 'menu') top--;
                    return top + dependTop + self.dh.outerHeight() <= wnd.scrollTop() + wnd.height();
                }
                var toAuto = function()
                {
                    try
                    {
                        var offset = depend.offset();
                        left = offset.left + depend.outerWidth();
                        top = offset.top - src.outerHeight();
                    } catch (e) { }
                }

                if (self.options.position == 'depend')
                {
                    toDepend();
                } else if (self.options.position == 'top')//定位于某元素上面
                {
                    if (!toTop()) toUnder();
                }
                else if (self.options.position == 'under')//定位于某元素下面
                {
                    if (!toUnder()) toTop();
                } else if (self.options.position == 'auto')
                {
                    toAuto();
                }
            }
            src.css({ left: Math.max(left, 0), top: Math.max(top, 0) });
        }

        // toUpdate 2011-05-07 zhangyu
        // 移除窗口在浏览器中随浏览器滚动条 滚动而滚动
        self.anchorToPos = function(obj)
        {
            var src = obj || self.dh;
            var wnd = $(window);
            var doc = $(document);
            var top = 0;
            var left = 0;
            /*
            if (!$.support.fixed)
            {
                top = doc.scrollTop();
                left = doc.scrollLeft();
            }
            */
             top = doc.scrollTop();
             left = doc.scrollLeft();
            //2011-1-11 原来anchorRight只用于分页果的提示，后来要求将位置定位到中间
            if (self.options.position == 'center' || self.options.type == 'modal')
            {
                if ($.support.fixed && self.options.anchorPosition)
                {
                    top += (wnd.height() - src.outerHeight()) / 2;
                    left += (wnd.width() - src.outerWidth()) / 2;
                    src.css({left: left, top: top });
                   // src.css({ position: 'fixed', left: left, top: top });
                } else
                {
                    top += (wnd.height() - src.outerHeight()) / 2;
                    left += (wnd.width() - src.outerWidth()) / 2;
                    src.css({ left: left, top: top });
                }
            } else if (self.options.position == 'anchorRight')
            {
                //分页的提示放到页面中间
                
                if ($.support.fixed)
                {
                    top += (wnd.height() - src.outerHeight()) / 2;
                    left += (wnd.width() - src.outerWidth()) / 2;
                    src.css({left: left, top: top })
                    //src.css({ position: 'fixed', left: left, top: top });
                } else
                {
                    top += (wnd.height() - src.outerHeight()) / 2;
                    left += (wnd.width() - src.outerWidth()) / 2;
                    src.css({ left: left, top: top });
                }
                /*
                if (self.options.top == 'center')
                {
                top += (wnd.height() - src.outerHeight()) / 2;
                } else
                {
                top += self.options.top;
                }
                src.css('left', '');
                if ($.support.fixed)
                {
                left = self.options.left - doc.scrollLeft();
                src.css({ position: 'fixed', right: left, top: top });
                } else
                {
                left = self.options.left - doc.scrollLeft();
                src.css({ right: left, top: top });
                }*/
            } else
            {
                if (self.options.top == 'center')
                {
                    top += (wnd.height() - src.outerHeight()) / 2;
                } else
                {
                    top += self.options.top;
                }
                if (self.options.left == 'center')
                {
                    left += (wnd.width() - src.outerWidth()) / 2;
                } else
                {
                    left += self.options.left;
                }
                
                src.css({ left: left, top: top });
                /*
                if ($.support.fixed)
                {
                    src.css({ position: 'fixed', left: left, top: top });
                } else
                {
                    src.css({ left: left, top: top });
                }
                */
            }
        }

        self.initOptions();
    }

    this.singleID = '';
    this._onbox = false;
    this._opening = false;
    this.zIndex = 999;
    var length = function()
    {
        return arrweebox.length;
    }

    //关闭唯一对话框
    $.fn.closeSingleDialog = function()
    {
        try
        {
            var container = $('#_dialog' + this.singleID);
            var context = container.data(contextData);
            context.close();
        } catch (e) { }
    }

    //关闭当前对话框
    $.fn.closeDialog = function()
    {
        try
        {
            var container = this.getDialog();

            var context = container.data(contextData);
            context.close();
        } catch (e) { alert(e.message); }
    }

    //获取当前对话框
    $.fn.getDialog = function()
    {
        return this.closest('._dialog');
    }

    //获取当前对话框的实例对象
    $.fn.getDialogItem = function()
    {
        var container = this.getDialog();
        return container.data(contextData);
    }

    //获取内容属性以构造dialog对象
    var getContentOption = function(content)
    {
        var contentType = 'html';
        if (/^#/.test(content))
        {
            contentType = 'selector';
        } else if (/\.(png|aspx|ashx|html|htm|asp)/i.test(content))
        {
            contentType = 'ajax';
        } else if (/\.(jpg|png|gif)$/i.test(content))
        {
            contentType = 'img';
        }
        else// if(/^(http:)|(https:)/.test(href))
        {
            contentType = 'html';
        }
        return { content: content, contentType: contentType };
    }

    //手动绑定
    $.fn.bindWindow = function(options)
    {
        var opt = options || {};
        var box = new weebox(opt);
        this.unbind('click').click($.proxy(box.show, box));
        return box;
    }

    //模式窗口
    $.fn.bindModal = function(options)
    {
        var opt = options || {};
        var content = getContentOption(opt.content || this.attr('href'));
        opt.title = opt.title || this.attr('title');
        opt.content = opt.content || content.content;
        //opt.animate = 'fade';
        opt.contentType = content.contentType;
        opt.type = opt.type || 'modal';
        opt.position = 'center';
        opt.showButton = opt.showButton || false;
        opt.draggable = false;
        opt.id = '_hover' + getID();
        this.singleID = opt.id;

        var options = options || {};
        if (options.boxid)
        {
            for (var i = 0; i < arrweebox.length; i++)
            {
                if (arrweebox[i].dh.attr('id') == options.boxid)
                {
                    arrweebox[i].close();
                    break;
                }
            }
        }
        var box = new weebox(opt);
        this.unbind('click').click(box.show);
        return box;
    }

    //非模式窗口
    $.fn.bindDialog = function(options)
    {
        var opt = options || {};
        var content = getContentOption(opt.content || this.attr('href'));
        opt.title = opt.title || this.attr('title');
        opt.content = opt.content || content.content;
        //opt.animate = 'fade';
        opt.contentType = content.contentType;
        opt.type = opt.type || 'dialog';
        opt.position = opt.depend || 'depend';
        opt.dependElement = this;
        opt.showButton = opt.showButton || false;
        opt.draggable = true;

        var box = new weebox(opt);
        this.unbind('click').click(box.show);
        return box;
    }

    //浮动窗口
    $.fn.bindHover = function(options)
    {
        var opt = options || {};
        var content = getContentOption(opt.content || this.attr('href'));
        opt.title = opt.title || this.attr('title');
        opt.content = opt.content || content.content;
        opt.animate = 'fade';
        opt.contentType = content.contentType;
        opt.type = opt.type || 'hover';
        opt.position = opt.depend || 'left';
        opt.dependElement = this;
        opt.draggable = true;
        opt.id = '_hover' + getID();
        this.singleID = opt.id;

        var box = new weebox(opt);
        this.unbind('click').click(box.show, box);
        return box;
    }

    //提示框
    $.fn.bindTooltip = function(opt)
    {
        opt = opt || {};
        if (opt.contentType)
        {
            opt.content = this.attr('title');
        } else
        {
            opt = $.extend(opt, getContentOption(this.attr('title')));
        }
        this.removeAttr('title');
        opt.dependElement = this;
        /*
        var tagname=this[0].tagName;
        var wrap=this;
        if(tagname=='INPUT' || tagname=='IMG')
        {
        this.wrap('<span style="border:red solid 0px;"></span>');
        wrap=this.closest('span');
        opt.dependElement=wrap;
        }else
        {
        opt.dependElement=this;
        }*/
        opt.type = 'tooltip';
        //opt.animate = 'fade';
        opt.position = opt.position || 'left';
        opt.draggable = false;
        opt.id = '_tooltip' + getID();
        this.singleID = opt.id;

        var box = new weebox(opt);
        var close = this.closeSingleDialog;
        //this.hover(box.show, self.closeSingleDialog);
        if (opt.keepHover)
        {
            this.hover(function()
            {
                //关闭所有其它已经显示的气泡
                $('._tooltip').each(function()
                {
                    var c = $(this).data(contextData);
                    if (c.options.id == box.options.id) return;
                    try
                    {
                        $(this).closeDialog();
                    } catch (e) { }
                });
                box.show();
            }, null);
        } else
        {
            this.hover(function()
            {
                //关闭所有其它已经显示的气泡
                $('._tooltip').each(function()
                {
                    var c = $(this).data(contextData);
                    if (c.options.id == box.options.id) return;
                    try
                    {
                        $(this).closeDialog();
                    } catch (e) { }
                });
                box.show();
            }, box.close);
        }
        return box;
    }

     // ZhangYu 20110-90-9
    //获取焦点事件的 提示框
    $.fn.bindfocusTooltip = function(opt)
    {
        opt = opt || {};
        if (opt.contentType)
        {
            opt.content = this.attr('title');
        } else
        {
            opt = $.extend(opt, getContentOption(this.attr('title')));
        }
        this.removeAttr('title');
        opt.dependElement = this;
        /*
        var tagname=this[0].tagName;
        var wrap=this;
        if(tagname=='INPUT' || tagname=='IMG')
        {
        this.wrap('<span style="border:red solid 0px;"></span>');
        wrap=this.closest('span');
        opt.dependElement=wrap;
        }else
        {
        opt.dependElement=this;
        }*/
        opt.type = 'tooltip';
        //opt.animate = 'fade';
        opt.position = opt.position || 'left';
        opt.draggable = false;
        opt.id = '_tooltip' + getID();
        this.singleID = opt.id;

        var box = new weebox(opt);
        var close = this.closeSingleDialog;
        //this.hover(box.show, self.closeSingleDialog);
        this.focus(function()
        {
            //关闭所有其它已经显示的气泡
            $('._tooltip').each(function()
            {
                var c = $(this).data(contextData);
                if (c.options.id == box.options.id) return;
                try
                {
                    $(this).closeDialog();
                } catch (e) { }
            });
            box.show();
        }).blur(function()
        {
             box.close();
        });
        return box;
    }

    //下拉菜单      2010-10-14  by dongzh
    $.fn.bindMenu = function(menu, options)
    {
        var opt = options || {};
        //opt.container = opt.container || 'body';
        opt.content = menu;
        opt.contentType = 'selector';
        opt.type = 'menu';
        opt.position = opt.position || 'under';
        opt.dependElement = this;
        opt.draggable = false;
        opt.id = '_menu' + getID();
        //opt.width = this.outerWidth();
        this.singleID = opt.id;

        //2011-1-5 取消了点击指定区域不关闭菜单的功能
        opt.keepHover = this;
        /*
        if (opt.keepHover)
        {
        if ($.isArray(opt.keepHover))
        {
        opt.keepHover.push(this);
        } else
        {
        opt.keepHover = [opt.keepHover, this];
        }
        } else
        {
        opt.keepHover = this;
        }*/

        var box = new weebox(opt);
        this.unbind('click').click(box.toggle);
        return box;
    };

    //消息框
    $.message = function(msg, options)
    {
        var opt = {};
        if (typeof options == 'function' || typeof options == 'string' || typeof options == 'number')
        {
            opt.onclose = options;
        } else
        {
            opt = $.extend(opt, options);
        }
        opt.type = 'message';
        opt.position = 'center';
        opt.contentType = 'html';
        opt.icon = opt.icon || 'success';
        opt.content = msg;
        //opt.animate = 'fade';
        opt.title = opt.title || '系统提示';
        opt.draggable = false;
        opt.id = '_tooltip' + getID();
        opt.showCancel = false;
        //opt.animate='slow';
        var box = new weebox(opt);
        box.show();
        return box;
    }

    //消息框
    $.fn.message = function(msg, options)
    {
        var opt = {};
        if (typeof options == 'function' || typeof options == 'string' || typeof options == 'number')
        {
            opt.onclose = options;
        } else
        {
            opt = $.extend(opt, options);
        }
        opt.type = 'message';
        opt.position = 'center';
        opt.contentType = 'html';
        opt.icon = opt.icon || 'success';
        opt.content = msg;
        //opt.animate = 'fade';
        opt.title = opt.title || '系统提示';
        opt.draggable = false;
        opt.id = '_tooltip' + getID();
        opt.showCancel = false;
        //opt.animate='slow';
        var box = new weebox(opt);
        box.show();
        return box;
    }

    //确认框
    $.confirm = function(msg, title, ok, cancell)
    {
        var opt = {};
        opt.src = this;
        opt.type = 'confirm';
        opt.position = 'center';
        opt.contentType = 'html';
        opt.icon = 'question';
        opt.content = msg;
        //opt.animate = 'fade';
        opt.draggable = false;
        opt.id = '_tooltip' + getID();
        //opt.okBtnName='是';
        //opt.cancelBtnName='否';
        if (typeof title == 'function')
        {
            opt.onok = title;
            opt.oncancell = ok;
        } else
        {
            opt.title = title;
            opt.onok = ok;
            opt.oncancel = cancell;
        }
        opt.title = opt.title || '系统提示';
        var box = new weebox(opt);
        box.show();
        return box;
    }

    //确认框
    $.fn.confirm = function(msg, title, ok, cancell)
    {
        var opt = {};
        opt.src = this;
        opt.type = 'confirm';
        opt.position = 'center';
        opt.contentType = 'html';
        opt.icon = 'question';
        opt.content = msg;
        //opt.animate = 'fade';
        opt.draggable = false;
        opt.id = '_tooltip' + getID();
        //opt.okBtnName='是';
        //opt.cancelBtnName='否';
        if (typeof title == 'function')
        {
            opt.onok = title;
            opt.oncancell = ok;
        } else
        {
            opt.title = title;
            opt.onok = ok;
            opt.oncancel = cancell;
        }
        opt.title = opt.title || '系统提示';
        var box = new weebox(opt);
        box.show();
        return box;
    }

    //创建一个对话框不自动显示
    $.dialog = function(options)
    {
        var box = new weebox(options);
        return box;
    }

    //打开指定的url并显示对话框
    $.showDialog = function(url, options)
    {
        var opt = options || {};
        opt.content = url;
        opt.contentType = opt.contentType || 'ajax';
        //if (typeof opt.animate == 'undefined') opt.animate = 'fade';
        opt.type = opt.type || 'dialog';
        opt.position = opt.depend || 'depend';
        opt.dependElement = $($.event.fix(event).target);
        opt.showButton = opt.showButton || false;
        opt.draggable = true;
        var box = new weebox(opt);
        box.show();
        return box;
    }

    //打开指定的url并以模式窗口显示对话框draggable
    $.showModal = function(url, options)
    {
        var opt = options || {};
        opt.content = url;
        opt.contentType = opt.contentType || 'ajax';
        //if (typeof opt.animate == 'undefined') opt.animate = 'fade';
        opt.type = 'modal';
        opt.showButton = opt.showButton || false;
        //opt.draggable = opt.draggable || false;
        var box = new weebox(opt);
        box.show();
        return box;
    }

    //提供定位于屏幕的某个位置的窗口显示
    $.anchor = function(msg, options)
    {
        var opt = options || {};
        opt.type = 'anchor';
        opt.position = opt.position || 'center';
        opt.content = msg;
        //opt.animate = 'fade';
        opt.contentType = 'html';
        opt.timeout = opt.timeout || 0;
        if (opt.icon == 'undefined') opt.icon = 'success';
        opt.draggable = false;
        opt.id = '_anchor' + getID();
        opt.showButton = false;
        var box = new weebox(opt);
        box.show();
        return box;
    }

    //显示一个消息提示，2秒钟消失
    $.anchorMsg = function(msg, opt)
    {
        opt = opt || {};
        if (typeof opt.timeout == 'undefined') opt.timeout = 2;
        //opt.timeout = 0;
        $.anchor(msg, opt);
    }

    $.showError = function(msg)
    {
        msg = msg || '非常抱歉，数据加载失败';
        var errorHtml =
    '            	<div class="floatlayer_wrong">' +
    '            		' + msg +
    '                </div>' +
    '               <div class="floatlayer_wrong_btn dialog_btn"><a class="btn2" onclick="$(this).closeDialog();"><span>关 闭</span></a></div>';
        $.showModal(errorHtml, { conentType: 'html' });
    }

    //关闭当前事件源所在的窗口
    /*
    $.closeDialog = function()
    {
    try
    {
    $($.event.fix((event) ? event : window.event).target).closeDialog();
    } catch (e)
    { }
    }*/
    
    
 $().ready(function()
    {		

		var dialogs=$(".dialog"),dialogLefts=$(".dialogLeft"),dialogRights=$('.dialogRight'),dialogTops=$('.dialogTop'),
		dialogUnders=$('.dialogUnder'),modals=$('.modal');
		for(var i=0;i<dialogs.length;i++){
			dialogs[i].bindDialog();
		}
		for(var i=0;i<dialogLefts.length;i++){
			dialogLefts[i].bindDialog({ depend: 'left' });
		}
		for(var i=0;i<dialogRights.length;i++){
			dialogRights[i].bindDialog({ depend: 'right' });
		}
		for(var i=0;i<dialogTops.length;i++){
			dialogTops[i].bindDialog({ depend: 'top' });
		}
		for(var i=0;i<dialogUnders.length;i++){
			dialogUnders[i].bindDialog({ depend: 'under' });
		}
		for(var i=0;i<modals.length;i++){
			modals[i].bindModal();
		}		
		var menus=$(".menu");
		for(var i=0;i<menus.length;i++){
			$(menus[i]).bindMenu();
		}
    });

})(jQuery);

